package jzqb.controller.admin;

import haha.life.common.CutPageBean;
import haha.life.common.PermissionTypeTool;
import haha.life.common.SysTool;
import haha.life.normal.TokenUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jzqb.annotation.PermissionCheck.PermissionCheck;
import jzqb.bo.CommonsBo;
import jzqb.common.Result;
import jzqb.service.ICommonsService;
import jzqb.vo.CommonsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Description: 意见回复
 *
 * @author BaiGe
 * @date: 2021/4/7 16:14
 * @Version 1.0
 */

@Api(tags = "意见回复接口")
@RestController
@RequestMapping("/admin/commons")
public class AdminCommonsController {

    @Autowired
    private ICommonsService commonsService;

    @ApiOperation(value = "查询意见回复")
    @PermissionCheck(permissionTypeList = {PermissionTypeTool.business_mgt})
    @GetMapping("/queryCommons")
    public Result queryCommons(@RequestParam(value = "startTime", required = false) String startTime,
                               @RequestParam(value = "endTime", required = false) String endTime,
                               @RequestParam(value = "status", required = false) String status,
                               @RequestParam(value = "page") Integer page,
                               @RequestParam(value = "pageSize") Integer pageSize) {
        CommonsBo commonsBo = new CommonsBo();
        commonsBo.setStart(page, pageSize);
        commonsBo.setStartTime(startTime);
        commonsBo.setEndTime(endTime);
        commonsBo.setPage(page);
        commonsBo.setPageSize(pageSize);
        commonsBo.setStatus(status);
        CutPageBean<CommonsVo> cutPageBean = commonsService.queryCommons(commonsBo);
        return Result.succ(cutPageBean);
    }


    //管理员处理意见反馈
    @ApiOperation(value = "修改某条意见回复")
    @PermissionCheck(permissionTypeList = {PermissionTypeTool.business_mgt})
    @PostMapping("/updateCommons")
    public Result updateCommons(@RequestBody CommonsBo commonsBo, HttpServletRequest request) {
        commonsBo.setReplyTime(SysTool.getCurrentTime(SysTool.dateFormat_milli));
        commonsBo.setReplier(TokenUtils.getCurrentUserId(request));
        commonsBo.setReadState(0);//每次处理,都将阅读状态设置为未读
        Boolean bl = commonsService.updateCommons(commonsBo);
        if (bl) {
            return Result.succ("处理成功");
        } else {
            return Result.succ("处理失败");
        }
    }

    @ApiOperation(value = "删除某条意见回复")
    @PermissionCheck(permissionTypeList = {PermissionTypeTool.business_mgt})
    @PostMapping("/delCommons")
    public Result delCommons(@RequestBody CommonsBo commonsBo) {
        Boolean bl = commonsService.delCommonsById(commonsBo.getId());
        if (bl) {
            return Result.succ("删除成功");
        } else {
            return Result.succ("删除失败");
        }
    }
}
